package tech.aistar.wyymusicplayer.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.aistar.wyymusicplayer.pojo.PlayListDetails;
import tech.aistar.wyymusicplayer.pojo.Result;
import tech.aistar.wyymusicplayer.pojo.Song;
import tech.aistar.wyymusicplayer.service.PlayListDetailsService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName: PlayListController
 * Package: tech.aistar.wyymusicplayer.controller
 * Description:
 *
 * @Author: JMOOL
 * @Create: 2025/3/6-09:36
 * @Version: v1.0
 */
@RestController
@RequestMapping("playlistDetails")
public class PlayListDetailsController {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private PlayListDetailsService playListService;

    @GetMapping
    public Result index() {
        // 获取歌单基础信息
        PlayListDetails playList = playListService.findPlayLists(1);

        // 获取歌单包含的歌曲ID列表
        List<Integer> songIds = playListService.selectSongIdsByPlaylistId(1);

        // 批量获取歌曲详细信息
        List<Song> songs = playListService.selectSongsByIds(songIds);

        // 构造返回数据结构
        Map<String, Object> data = new HashMap<>();
        data.put("playList", playList);
        data.put("songs", songs);

        return new Result("200", "数据获取成功", data);
    }
}
